package cn.org.qary.Interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (request.getSession().getAttribute("user") == null) {
            String project_name = (String)request.getServletContext().getAttribute("project_name");
            response.sendRedirect(String.format("%s/login.jsp", project_name));
            return false;
        }
        else {
            return true;
        }

    }
}
